package com.hongdee.insurance.itemprice.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.insurance.itemprice.entity.TInsuranceItemPrice;
import com.hongdee.insurance.itemprice.service.ITInsuranceItemPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Mr. Xu on 2017/5/3.
 */
@RestController
@RequestMapping("/insurance/itemPrice")
public class TInsuranceItemPriceController {
    @Autowired
    private ITInsuranceItemPriceService itInsuranceItemPriceService;

    /**
     * 保险项目价格维护
     * @param uid
     * @param token
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestBody TInsuranceItemPrice data) throws Exception {
        this.itInsuranceItemPriceService.save(data, uid);
        ResultEntity res = new ResultEntity();
        res.setMsg("保存成功！");
        res.setSuccess(true);
        return res;
    }
    /**
     * 保险项目为维护分页查询
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestBody Map data) throws Exception {
        Map map = this.itInsuranceItemPriceService.page(uid, start, limit, data);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }
    /**
     * 单条保险项目金额维护删除
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/del")
    @ResponseBody
    public ResultEntity singleSave(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "id", defaultValue = "") String id) throws Exception {

        this.itInsuranceItemPriceService.del(id);
        ResultEntity res = new ResultEntity();
        res.setSuccess(true);
        res.setMsg("删除成功！");
        return res;
    }
}
